package com.jxb;

import java.io.IOException;
import java.io.InputStream;

import javax.annotation.Resource;

import com.jxb.bojiaoMybatis.BojiaoMybatisScan;
import com.jxb.importtest.BojiaoImport;
import com.jxb.qiantao.A;
import com.jxb.qiantao.B;
import com.jxb.service.BeanCreate;
import com.jxb.service.IgnoreDependencyTest;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.*;

import com.jxb.service.OrderService;
import com.jxb.service.UserService;

@Configuration
@ComponentScan(value = "com.jxb")
// @Import(BojiaoImport.class)
@BojiaoMybatisScan(value = "com.jxb.mapper")
@MapperScan(value = "com.jxb.mapper")
//@PropertySource("classpath:spring.properties")
public class AppConfig {

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        return sqlSessionFactory;
    }


    // @Bean(autowire = Autowire.BY_NAME)
    // public IgnoreDependencyTest ignoreDependencyTest() {
    //     return new IgnoreDependencyTest();
    // }
    //
    // @Bean
    // public BeanCreate beanCreate() {
    //     return new BeanCreate();
    // }
    //
    // @Bean
    // public BeanCreate beanCreate(UserService userService) {
    //     return new BeanCreate(userService);
    // }

    // @Bean(autowire = Autowire.BY_NAME)
    // public UserService userService() {
    //     return new UserService();
    // }

     @Bean
     public A a() {
         System.out.println(b());
         System.out.println(b());
         return new A();
     }

    @Bean
    public B b() {
        return new B();
    }
//
//    @Bean
//    public OrderService orderService1() {
//        return new OrderService();
//    }

}
